// ************************************************
// ACorns WCF Dynamic Client Proxy
// Copyright 2007 (C) ACorns Trading (www.acorns.com.au) (Corneliu I. Tusnea)
// corneliu@acorns.com.au
// http://www.acorns.com.au/blog/?p=142
// This package is provided "AS IS," without express or implied warranty of any kind, and may be used and modified.
// This package may be used in corporate applications without any pretence.
// Please keep this note
// ************************************************


using System;
using System.ComponentModel;
using System.ServiceModel;

namespace ACorns.WCF.DynamicClientProxy
{
	/// <summary>
	/// Class that can be used with PolicyInjection. Dynamically generated classes will inherit from this class.
	/// This class will also take care to unwrap any FaultException and extract and throw the original exception.
	/// </summary>
	[EditorBrowsable(EditorBrowsableState.Never)] 
	public abstract class WCFReusableFaultWrapperClientProxy<T> : WCFReusableClientProxy<T> where T : class
	{
		protected WCFReusableFaultWrapperClientProxy(string configName)
			: base(configName)
		{
		}

		protected virtual void HandleFault<TFaultDetail>(FaultException<TFaultDetail> fault)
		{
			Exception ex = fault.Detail as Exception;
			if (ex != null)
			{
				throw ex;
			}
			// else do nothing, the calee will throw the original fault
		}
	}
}